﻿using Basic.FormGatewaryModular.Interface;
using Basic.FormRemoteModel;
using Basic.FormRemoteModel.PhysicalQuery.Model;
using WeDonekRpc.ApiGateway.Attr;
using WeDonekRpc.Helper;
using WeDonekRpc.Helper.Validate;
using WeDonekRpc.HttpApiGateway;
using WeDonekRpc.HttpApiGateway.Model;

namespace Basic.FormGatewaryModular.Api
{
    [ApiRouteName("/form/physical/query/{name}")]
    internal class PhysicalQueryApi : ApiController
    {
        private readonly IPhysicalQueryService _Service;

        public PhysicalQueryApi ( IPhysicalQueryService service )
        {
            this._Service = service;
        }
        public PhysicalQueryData[] Gets ( [NumValidate("form.id.error", 1)] long formId, [EnumValidate("form.layout.location.error", typeof(LayoutLocation))] LayoutLocation location )
        {
            return this._Service.Gets(formId, location);
        }
        public long Add ( PhysicalQueryAdd data )
        {
            return this._Service.Add(data);
        }
        public void SetSort ( LongNullParam<int>[] sort )
        {
            this._Service.SetSort(sort.ConvertAll(a => new KeyValuePair<long, int>(a.Id, a.Value)));
        }

        public void Delete ( [NumValidate("form.phy.query.error", 1)] long id )
        {
            this._Service.Delete(id);
        }

        public PhysicalQueryDto Get ( [NumValidate("form.phy.query.error", 1)] long id )
        {
            return this._Service.Get(id);
        }

        public PhysicalQueryBody GetBody ( [NumValidate("form.id.error", 1)] long formId )
        {
            return this._Service.GetBody(formId);
        }

        public bool Set ( LongParam<PhysicalQuerySet> set )
        {
            return this._Service.Set(set.Id, set.Value);
        }
    }
}
